package com.kurancy.domain;

import java.util.Date;

import javax.persistence.EntityManager;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.TypedQuery;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.tostring.RooToString;

@RooJavaBean
@RooToString
@RooJpaActiveRecord(finders = { "findFaqsByIsActiveNot, findActiveFaqsGroupByGroupNameOrderBySortOrder" })
public class Faq {

    @NotNull
    private String groupName;

    @NotNull
    private int groupSortOrder;

    @NotNull
    private int sortOrder;

    @NotNull
    @Size(max = 250)
    private String question;

    @NotNull
    @Size(max = 250)
    private String answer;

    @NotNull
    @Value("true")
    private Boolean isActive;

    @NotNull
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(pattern = "MM/dd/yyyy hh:mm:ss a")
    private Date createdOn;

    @NotNull
    private Boolean important;
    
    public static TypedQuery<Faq> findActiveFaqsGroupByGroupNameOrderBySortOrder() {
        EntityManager em = Faq.entityManager();
        TypedQuery<Faq> q = em.createQuery("SELECT o FROM Faq AS o WHERE o.isActive = :isActive order by o.sortOrder asc", Faq.class);
        q.setParameter("isActive", true);
        return q;
        
    }
}
